package org.ghub.pdf;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class fileConverter {
	
	private String outputUrl;
	private String content;
	private String baseUrl;
		
	public fileConverter() {
	}	
	
	public fileConverter(String outputUrl, String content, String baseUrl) {
		this.outputUrl = outputUrl;
		this.content = content;
		this.baseUrl = baseUrl;
	}

	public void exportToTxt() throws IOException
	{
		FileOutputStream fop = null;
		File file;
		String content = this.getContent();
		file = new File(this.getBaseUrl()+""+this.getOutputUrl());
		//file.delete();//for replace
		fop = new FileOutputStream(file);
		// if file doesnt exists, then create it
		if (!file.exists()) {
			file.createNewFile();
		}
		// get the content in bytes
		byte[] contentInBytes = content.getBytes();
		fop.write(contentInBytes);
		fop.flush();
		fop.close();
		System.out.println("Successfully converted to txt");
	}
	
	public String getOutputUrl() {
		return outputUrl;
	}
	public void setOutputUrl(String outputUrl) {
		this.outputUrl = outputUrl;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getBaseUrl() {
		return baseUrl;
	}
	public void setBaseUrl(String baseUrl) {
		this.baseUrl = baseUrl;
	}		

}
